# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Contributor: Łukasz Jendrysik <scadu@yandex.com>
# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Contributor: Jakub Skrzypnik <j.skrzypnik@openmailbox.org>
# Maintainer: Alex McGrath <amk@amk.ie>
pkgname=mpv
# intentionally git, see
# https://github.com/mpv-player/mpv#release-cycle
# the stable releases are just arbitrary git, so we can update more often.
# it's the same stability policy regardless
pkgver=0.38.0
pkgrel=0
_gitrev=02254b92dd237f03aa0a151c2a68778c4ea848f9
pkgdesc="Video player based on MPlayer/mplayer2"
url="https://mpv.io/"
license="GPL-2.0-or-later"
arch="all"
makedepends="
	alsa-lib-dev
	ffmpeg-dev
	jack-dev
	libao-dev
	libarchive-dev
	libass-dev
	libbluray-dev
	libcaca-dev
	libcdio-paranoia-dev
	libdvdnav-dev
	libplacebo-dev
	libva-dev
	libxext-dev
	libxinerama-dev
	libxkbcommon-dev
	libxpresent-dev
	libxrandr-dev
	libxscrnsaver-dev
	libxv-dev
	mesa-dev
	meson
	pipewire-dev
	pulseaudio-dev
	py3-docutils
	rubberband-dev
	shaderc-dev
	sndio-dev
	uchardet-dev
	vulkan-headers
	vulkan-loader-dev
	wayland-dev
	wayland-protocols
	zimg-dev
	zlib-dev
	"
subpackages="
	$pkgname-dbg
	$pkgname-doc
	$pkgname-libs
	$pkgname-dev
	$pkgname-bash-completion
	$pkgname-zsh-completion
	"
source="https://github.com/mpv-player/mpv/archive/$_gitrev/mpv-$_gitrev.tar.gz
meson-libcaca-version.patch"
builddir="$srcdir/mpv-$_gitrev"

case "$CARCH" in
ppc64le|riscv64|loongarch64)
	makedepends="$makedepends lua5.2-dev"
	;;
*)
	makedepends="$makedepends luajit-dev"
	;;
esac

case "$CARCH" in
# the tests expect a little endian host
s390x) options="$options !check" ;;
esac

# secfixes:
#   0.27.0-r3:
#     - CVE-2018-6360

prepare() {
	default_prepare

	echo "${pkgver%_git*}-$_gitrev" > VERSION
}

build() {
	CFLAGS="$CFLAGS -O2" \
	CXXFLAGS="$CXXFLAGS -O2" \
	abuild-meson \
		-Db_lto=true \
		-Dalsa=enabled \
		-Dbuild-date=false \
		-Dcaca=enabled \
		-Dcdda=enabled \
		-Ddvdnav=enabled \
		-Degl-drm=enabled \
		-Degl-wayland=enabled \
		-Degl-x11=enabled \
		-Degl=enabled \
		-Dgl=enabled \
		-Djack=enabled \
		-Dlibmpv=true \
		-Dpulse=enabled \
		-Dsndio=enabled \
		-Dtests="$(want_check && echo true || echo false)" \
		-Duchardet=enabled \
		-Dvdpau=disabled \
		-Dvulkan=enabled \
		-Dx11=enabled \
		. output

	meson compile -C output
}

check() {
	meson test --no-rebuild --print-errorlogs -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output

	install -Dm644 "$builddir"/DOCS/*.rst "$builddir"/DOCS/*.md \
		-t "$pkgdir"/usr/share/doc/$pkgname/

	# Move example configuration files to subdirectory
	mkdir -p "$pkgdir"/usr/share/doc/mpv/examples
	mv "$pkgdir"/usr/share/doc/mpv/*.conf \
		"$pkgdir"/usr/share/doc/mpv/examples/
}

sha512sums="
bacd7b0da1a82d1999556c0c4f8515f5c2e922ac2920d4b3dae85dc77f7c20475273f3e7772078cb77b2ec863a874047bcdf6e52f3dc43a5a2c8b16bacd19d3a  mpv-02254b92dd237f03aa0a151c2a68778c4ea848f9.tar.gz
4ff107b15c7d124a22547f73b10fa7cbaf247be27717474d875fa5db9652ae3b19b6801a069b066eb9566e66a4882257e09b9424f9fe95a477bd2deffa72c890  meson-libcaca-version.patch
"
